#!/usr/bin/env python
# coding=utf-8

if __name__ == '__main__':
    """ for file debug"""
    import sys,os
    sys.path.insert(0,os.path.join( os.getcwd(), '..' ))

import vavava.work_queue
import tracker.track_gripper

__author__ = 'vavava'


class Spider(tracker.track_gripper.TrackGripper,vavava.work_queue.work):
    def __init__(self,dbObj,itemID="",debug_level=0,soc_timeout=10,log=None):
        tracker.track_gripper.TrackGripper.__init__(self,dbObj,itemID,debug_level,soc_timeout,log)
        vavava.work_queue.work.__init__(self,log)

    def do(self):
        self.track()


def main():
    import vavava.work_queue,time
    import tracker.trackData
    workingLine=vavava.work_queue.WorkQueue()
    workingLine.Start()
    item_list=['MHB0012826', 'MHB0014533', 'MHB0015094', 'MHB0015088', 'MHB0015168',
               'MHB0015572', 'MHB0015729', 'UCL0000623','UQV0000030', 'UCL0000816',
               'MHB0016239', 'UQV0000071', 'UCL0000935', 'UCL0001042', 'UCL0001036',
               'UCL0001080', 'UQV0000117', 'UQV0000126']
    dbo = tracker.trackData.DBObject(host="localhost",port=3306,
        user="root",passwd="root",db="wr_trace",log=None)
    try:
        for each in item_list:
            print("==================== add %s"%each)
            spider = Spider(dbObj=dbo,itemID=each)
            workingLine.QueueWork(spider)
            time.sleep(0.5)
    except(KeyboardInterrupt):
        print('main thread(%f):stop'%time.clock())
        workingLine.Stop()
        print('main thread(%f):stopped'%time.clock())

if __name__ == '__main__':
    main()

